<?php
/**
 * Copyright 2008 francissem (http://www.webmoss.net)(francissem@gmail.com)
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 		http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @author francissem
 * @copyright 2008 francissem (http://www.webmoss.net)(francissem@gmail.com)
 * @license http://www.apache.org/licenses/LICENSE-2.0
 */
require_once(dirname(__FILE__)."/Controller/Request.php");
class Core_Controller{
	protected $request;
	protected $response;
	protected $interrupt_response;

	function classifyRequest($headers,$all_site_tags){
		if($headers["REQUEST_METHOD"]=="GET"){
			return Core_Controller_Request::factory("Content",$headers,$all_site_tags);
		}
	}

	function setRequest($request){
		$this->request = $request;
	}

	function getRequest(){
		return $this->request;
	}

	function setResponse(Core_Controller_Response $response){
		$this->response = $response;
	}

	function setInterruptResponse(Core_Controller_Response $response){
		if(isset($this->interrupt_response)) {
			require_once(dirname(__FILE__)."/Controller/Exception.php");
			throw new Core_Controller_Exception("Interrupt response already exist");
		}
		$this->interrupt_response = $response;
	}

	function getResponse(){
		return $this->response;
	}

	function response(){
		if(method_exists($this,"onBeforeResponse")){
			$this->onBeforeResponse();
		}
		if(Core_System::GetSetting("general","mode")=="debug")
		Core_Module::getModule($this->request->getModuleName())->buildPublicResource();
		if(!isset($this->response)){
			if($this->request instanceof Core_Controller_Request_Content){
				require_once("Core/Controller/Response.php");
				$r = new Core_Controller_Response();
				$r->setContentFile($this->request->getContentFile());
				$r->setContent($c);
			}
		}else{
			$r = $this->response;
		}
		$r->out();
	}
}
?>